package com.easy.service.impl;

import com.easy.annotation.LogMethod;
import com.easy.bean.Medicine;
import com.easy.mapper.MedicineMapper;
import com.easy.service.MedicineService;
import com.easy.util.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MedicineServiceImpl implements MedicineService {

    @Autowired
    private MedicineMapper medicineMapper;

    @Override
    public Object page(Page page, Medicine medicine) {
        // 查询总条数
        int count = medicineMapper.count(medicine);
        page.setCount(count);
        // 查询分页数据
        List<Medicine> list = medicineMapper.page(medicine, page);
        page.setData(list);
        return page;
    }

    @Override
    @LogMethod(serviceName = "新增药品信息")
    public Medicine add(Medicine medicine) {
        medicineMapper.add(medicine);
        // 新增后返回完整数据
        return medicineMapper.one(medicine.getId());
    }

    @Override
    @LogMethod(serviceName = "删除药品信息")
    public int del(Integer id) {
        return medicineMapper.del(id);
    }

    @Override
    @LogMethod(serviceName = "修改药品信息")
    public Medicine edit(Medicine medicine) {
        medicineMapper.edit(medicine);
        // 编辑后返回更新的数据
        return medicineMapper.one(medicine.getId());
    }

    @Override
    @LogMethod(serviceName = "查询药品信息")
    public List<Medicine> all(Medicine medicine) {
        return medicineMapper.all(medicine);
    }

    @Override
    @LogMethod(serviceName = "查询药品信息")
    public Medicine one(Integer id) {
        return medicineMapper.one(id);
    }
}
